package com.cn.bean;

import org.dom4j.Element;

import com.cn.xc.utils.XmlBeanUtil;

/**
 * @author sushy
 * @date 2016-3-23
 */
public abstract class SimpleBean implements java.io.Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 序列化
	 * 
	 * @return
	 */
	public Element serialize() {
		return XmlBeanUtil.serialize(this);
	}

	/**
	 * 序列化
	 * 
	 * @return
	 */
	public Element serialize(String localName) {
		return XmlBeanUtil.serialize(this, localName);
	}

	/**
	 * 反序列化
	 * 
	 * @param localEle
	 */
	public void unserialize(Element localEle) {
		XmlBeanUtil.unserialize(this, localEle);
	}

	/**
	 * 输出XML
	 * 
	 * @param encoding
	 * @return
	 */
	public String asXml(String encoding) {
		return XmlBeanUtil.ele2Xml(serialize(), encoding);
	}

	/**
	 * 反序列化
	 * 
	 * @param xml
	 * @param encoding
	 * @return
	 */
	public void asBean(String xml) {
		Element rootCopyEle = XmlBeanUtil.xml2Ele(xml);
		XmlBeanUtil.unserialize(this, rootCopyEle);
	}

	/**
	 * 输出文本
	 * 
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return serialize().asXML();
	}

}
